<template>
  <div class="app-container search-table-box aidex-table">
    <el-card shadow="never" ref="queryRef" style="margin-bottom: 12px;" class="search_card" v-show="showSearch">
      <div class="filter-container">
        <div class="search_box">
          <el-form :model="queryParams" ref="queryForm" label-width="80px" size="mini">
            <el-row :gutter="2">
              <el-row :gutter="2">
                <el-col :md="5" >
                  <el-form-item prop="searchValues">
                    <el-select
                      v-model="queryParams.searchValues"
                      multiple
                      filterable
                      remote
                      reserve-keyword
                      clearable
                      placeholder="请输入组织名称"
                      :remote-method="remoteSearchValue"
                      @change="handleQuery"
                      :loading="remoteSearchValueLoading"
                      style="width: 415px;margin-left: -78px"
                    >
                      <el-option
                        v-for="item in searchValueOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :md="6" align="right">
                  <el-form-item>
                    <el-button class="filter-item" type="primary" @click="handleQuery">搜索</el-button>
                    <el-button class="filter-item" style="margin-left: 8px" @click="resetQuery">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-row>
          </el-form>
        </div>
      </div>
    </el-card>
    <el-card shadow="never" >
      <template #header>
        <el-row>
          <el-col :span="8">
            <div class="card-header">
              <el-button disabled type="text">拆分规则信息</el-button>
            </div>
          </el-col>
          <el-col :span="16">
            <div class="btn_box" align="right" style="float: right;">
              <el-button
                class="filter-item"
                style="margin-left: 8px;"
                icon="el-icon-download"
                @click="handleExport"
                size="mini"
                v-hasPermi="['saleconfig:split:export']"
              >导出</el-button>
              <right-toolbar :showSearch.sync="showSearch" :columns.sync="columns" :columnsKey.sync="columnsKey" @showSearchFun="showSearchFun" @queryTable="getList" :tableKey.sync="tableKey"></right-toolbar>
            </div>
          </el-col>
        </el-row>
      </template>

      <el-table
              border
              stripe
              default-expand-all
              ref="tableRef"
              :key="tableKey"
              v-loading="loading"
              :data="splitList"
              @selection-change="handleSelectionChange"
              :row-style="rowClass"
              :header-cell-style= "{
                'font-size': '14px !important',
                'font-weight': '500 !important',
                'color': 'rgb(0 0 0)',
                'background-color': 'rgb(205 224 255)',
              }"
              highlight-current-row style="width: 100%;"
              :height="tableHeight"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" type="index" align="center" width="55">
          <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <template v-for="item in columns">
<!--          <el-table-column label="公司" align="center" prop="siteName"  v-if="item.visible && item.label=='公司'" show-overflow-tooltip  width="160"/>-->
          <el-table-column label="票据限额类型" align="center" prop="billTypeName"  v-if="item.visible && item.label=='票据限额类型'" show-overflow-tooltip width="150"/>
          <el-table-column label="拆分限额" align="center" prop="splitTypeName"  v-if="item.visible && item.label=='拆分限额'" show-overflow-tooltip width="180"/>
          <el-table-column label="普票" align="center" prop="generalTicket"  v-if="item.visible && item.label=='普票'" show-overflow-tooltip width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.splitType != 0">{{scope.row.generalTicket}}</span>
              <span v-else>*最大额度*</span>
            </template>
          </el-table-column>
          <el-table-column label="专票" align="center" prop="specialTicket"  v-if="item.visible && item.label=='专票'" show-overflow-tooltip width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.splitType != 0">{{scope.row.specialTicket}}</span>
              <span v-else>*最大额度*</span>
            </template>
          </el-table-column>
          <el-table-column label="电普" align="center" prop="electricTicket"  v-if="item.visible && item.label=='电普'" show-overflow-tooltip width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.splitType != 0">{{scope.row.electricTicket}}</span>
              <span v-else>*最大额度*</span>
            </template>
          </el-table-column>
          <el-table-column label="电专" align="center" prop="engineerTicket"  v-if="item.visible && item.label=='电专'" show-overflow-tooltip width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.splitType != 0">{{scope.row.specialTicket}}</span>
              <span v-else>*最大额度*</span>
            </template>
          </el-table-column>
          <el-table-column label="限额拆分规则" align="center" prop="splitRuleName"  v-if="item.visible && item.label=='限额拆分规则'" show-overflow-tooltip width="200"/>
          <el-table-column label="拆分规则顺序" align="center" prop="splitSequenceName"  v-if="item.visible && item.label=='拆分规则顺序'" show-overflow-tooltip width="160"/>
          <el-table-column label="拆分行数" align="center" prop="splitRowsName"  v-if="item.visible && item.label=='拆分行数'" show-overflow-tooltip width="120"/>
          <el-table-column label="最大行数" align="center" prop="maxRows"  v-if="item.visible && item.label=='最大行数'" show-overflow-tooltip width="100"/>
        </template>

        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="80" fixed="right">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['saleconfig:split:edit']"
            >编辑</el-button>
          </template>
        </el-table-column>
        <div slot="empty">
          <svg-icon icon-class="search-none" style="font-size: 64px;" />
          <p>暂无数据</p>
        </div>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改拆分规则对话框 -->
      <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="1000px" top="10vh" append-to-body>
        <div style="height: 490px;overflow: auto; padding: 12px 24px;">
          <el-form ref="form" size="small" :model="form" :rules="rules" label-position="right" label-width="120px">
            <el-row :gutter="24">
              <el-col :span="24">
                <el-form-item label="票据限额类型:" prop="billType">
                  <el-radio-group v-model="form.billType">
                    <el-radio :label="1">含税</el-radio>
                    <el-radio :label="0">不含税</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="拆分限额:" prop="splitType">
                  <el-radio-group v-model="form.splitType">
                    <el-radio :label="0">最大额度</el-radio>
                    <el-radio :label="1">自定义额度</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="5"  v-if="form.splitType == 1">
                <el-form-item label="普票:" prop="generalTicket">
                  <el-input-number v-model="form.generalTicket" placeholder="请输入普票" controls-position="right" :min="1" :precision="8"/>
                </el-form-item>
              </el-col>
              <el-col :span="5" v-if="form.splitType == 1">
                <el-form-item label="专票:" prop="specialTicket">
                  <el-input-number v-model="form.specialTicket" placeholder="请输入专票" controls-position="right" :min="1" :precision="8"/>
                </el-form-item>
              </el-col>
              <el-col :span="5" v-if="form.splitType == 1">
                <el-form-item label="电普:" prop="electricTicket">
                  <el-input-number v-model="form.electricTicket" placeholder="请输入电普" controls-position="right" :min="1" :precision="8"/>
                </el-form-item>
              </el-col>
              <el-col :span="5" v-if="form.splitType == 1">
                <el-form-item label="电专:" prop="engineerTicket">
                  <el-input-number v-model="form.engineerTicket" placeholder="请输入电专" controls-position="right" :min="1" :precision="8"/>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <div style="margin: -10px 0 10px 100px;">
                  <el-link type="info" disabled icon="el-icon-info">当自定义额度拆出的发票超过开票限额时可能会导致拆分失败，请您知悉</el-link>
                </div>
              </el-col>
              <el-col :span="24">
                <el-form-item label="限额拆分规则:" prop="splitRule">
                  <el-radio-group v-model="form.splitRule">
                    <el-radio :label="0">单价不变拆分数量（取整）</el-radio>
                    <el-radio :label="1">单价不变拆分数量（取小数）</el-radio>
                    <el-radio :label="2">数量不变拆分单价</el-radio>
                    <el-radio :label="3">总计数量不变拆分单价</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="拆分规则顺序:" prop="splitSequence">
                    <el-radio-group v-model="form.splitSequence">
                    <el-radio :label="0">按货物明细顺序</el-radio>
                    <el-radio :label="1">按最小张数</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="拆分行数:" prop="splitRows">
                  <template slot="label">
                    <span>拆分行数:</span>
                    <el-tooltip placement="top">
                      <div slot="content">
                        开启后，待开发票商品超过8行不再自动转为清单开具，
                        <br/>
                        将直接开具下一张发票，该配置不适用于成品油发票，
                        <br/>
                        成品油发票不支持清单开具，若超过指定行数将自动拆分
                        <br/>
                        为多张发票
                      </div>
                      <i class="el-icon-question"></i>
                    </el-tooltip>
                  </template>
                  <el-radio-group v-model="form.splitRows">
                    <el-radio :label="0">转为清单开具</el-radio>
                    <el-radio :label="1">拆分多张发票</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="最大行数设为:" prop="maxRows">
                  <el-select v-model="form.maxRows" placeholder="请选择" size="mini" style="width: 120px;">
                    <el-option key="1" label="1" value="1"></el-option>
                    <el-option key="2" label="2" value="2"></el-option>
                    <el-option key="3" label="3" value="3"></el-option>
                    <el-option key="4" label="4" value="4"></el-option>
                    <el-option key="5" label="5" value="5"></el-option>
                    <el-option key="6" label="6" value="6"></el-option>
                    <el-option key="7" label="7" value="7"></el-option>
                    <el-option key="8" label="8" value="8"></el-option>
                    <el-option key="q" label="强制开具清单" value="q"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary"  size="mini" @click="submitForm">确 定</el-button>
          <el-button  size="mini" @click="cancel">取 消</el-button>
        </div>
      </el-dialog>

      <!-- 查询条件-公司-弹出查询 -->
      <el-dialog v-dialogDrag  :close-on-click-modal="false" title="查询条件-公司查询" :visible.sync="searchsiteCodeDialogOpen" width="800px" append-to-body>
        <div class="dialog_box" style="height:550px;">
            <el-form label-position="left" :model="searchsiteCodeQueryParams" :inline="true"  ref="searchsiteCodeQueryForm" label-width="88px" >
                <el-form-item  prop="searchsiteCodeSearchValue">
                    <el-input
                            v-model="searchsiteCodeQueryParams.searchValue"
                            size="mini"
                            placeholder="请输入编码或名称查询公司"
                            @keyup.enter.native="handleSearchsiteCodeQuery"
                            clearable
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleSearchsiteCodeQuery">查询</el-button>
                </el-form-item>
            </el-form>
            <el-table v-loading="searchsiteCodeSelectLoading" :data="searchsiteCodeList"
                      height="400"
                      @row-click="handleSearchsiteCodeRowClick"
                      ref="searchsiteCodeMultipleTable"
                      :row-key="getSearchsiteCodeListRowKey"
                      :row-style="{height:2+'px'}"
                      :header-cell-style= "{
                        'font-size': '14px !important',
                        'font-weight': '500 !important',
                        'background-color':'rgb(241 241 241 / 52%)'
                      }"
                      :cell-style="{padding:'2px 4px'}"
                      border
                      @selection-change="handleSearchsiteCodeSelectionChange">
                <el-table-column type="selection" width="55" align="center"/>
                <!-- 数据 -->
                <el-table-column prop="siteCode" label="组织编码" width="180"></el-table-column>
                <el-table-column prop="siteName" label="组织名称" ></el-table-column>
            <el-table-column prop="propertyTypeName" label="性质" width="150"></el-table-column>
            </el-table>
            <pagination
                    v-show="searchsiteCodeTotal>0"
                    :total="searchsiteCodeTotal"
                    :page.sync="searchsiteCodeQueryParams.pageNum"
                    :limit.sync="searchsiteCodeQueryParams.pageSize"
                    @pagination="getSearchsiteCodeList"
            />
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button size="mini" type="primary" @click="confirmSearchsiteCode">确 定</el-button>
            <el-button size="mini"   @click="searchsiteCodeCancel">取 消</el-button>
        </div>
    </el-dialog>

      <!-- 编辑-公司-弹出查询 -->
      <el-dialog v-dialogDrag  :close-on-click-modal="false" title="编辑拆分规则-公司选择" :visible.sync="siteCodeDialogOpen" width="800px" append-to-body>
        <div class="dialog_box" style="height:550px;">
            <el-form label-position="left" :model="siteCodeQueryParams" :inline="true"  ref="siteCodeQueryForm" label-width="88px" >
                <el-form-item  prop="siteCodeSearchValue">
                    <el-input
                            v-model="siteCodeQueryParams.searchValue"
                            size="mini"
                            placeholder="请输入编码或名称查询公司"
                            @keyup.enter.native="handlesiteCodeQuery"
                            clearable
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handlesiteCodeQuery">查询</el-button>
                </el-form-item>
            </el-form>
            <el-table v-loading="siteCodeSelectLoading" :data="siteCodeList"
                      height="400"
                      @row-click="handlesiteCodeRowClick"
                      ref="siteCodeSingleTable"
                      :row-key="getsiteCodeListRowKey"
                      :row-style="{height:2+'px'}"
                      :header-cell-style= "{
                        'font-size': '14px !important',
                        'font-weight': '500 !important',
                        'background-color':'rgb(241 241 241 / 52%)'
                      }"
                      :cell-style="{padding:'2px 4px'}"
                      border
                      @selection-change="handlesiteCodeSelectionChange">
                <el-table-column label="选择" width="60">
            　　　　<template slot-scope="scope">
            　　　　　　<el-radio v-model="siteCodeDialogRadio" :label="scope.row"><i></i></el-radio>
            　　　　</template>
            　　 </el-table-column>
                <!-- 数据 -->
                <el-table-column prop="companycode" label="公司代码" width="180"></el-table-column>
                <el-table-column prop="companyname" label="公司名称" ></el-table-column>
                <el-table-column prop="remark" label="备注" width="120"></el-table-column>
            </el-table>
            <pagination
                    v-show="siteCodeTotal>0"
                    :total="siteCodeTotal"
                    :page.sync="siteCodeQueryParams.pageNum"
                    :limit.sync="siteCodeQueryParams.pageSize"
                    @pagination="getsiteCodeList"
            />
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button size="mini" type="primary" @click="confirmsiteCode">确 定</el-button>
            <el-button size="mini" @click="siteCodeCancel">取 消</el-button>
        </div>
    </el-dialog>




    </el-card>
  </div>
</template>

<script>
import { listSplit, getSplit, delSplit, addSplit, updateSplit } from "@/api/saleconfig/split";
import { listCompany as listcompany, getCompany as getcompany } from "@/api/core/company";
/* 城市列表 **/
import { provinceList, cityList, districtList } from "@/api/system/city";

export default {
  name: "Split",
  data() {
    return {
      advanced: false,
      tableHeight: this.getInitTableHeight(),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      tableKey: 5,
      //
      columnsKey: 'split',
      // 自定义列
      columns: [
          // {
          //     key: 0,
          //     label: `公司`,
          //     visible: true
          // },
          {
              key: 3,
              label: `票据限额类型`,
              visible: true
          },
          {
              key: 4,
              label: `拆分限额`,
              visible: true
          },
          {
              key: 5,
              label: `普票`,
              visible: true
          },
          {
              key: 6,
              label: `专票`,
              visible: true
          },
          {
              key: 7,
              label: `电普`,
              visible: true
          },
          {
              key: 8,
              label: `电专`,
              visible: true
          },
          {
              key: 9,
              label: `限额拆分规则`,
              visible: true
          },
          {
              key: 10,
              label: `拆分规则顺序`,
              visible: true
          },
          {
              key: 1,
              label: `拆分行数`,
              visible: true
          },
          {
              key: 2,
              label: `最大行数`,
              visible: true
          },
          {
              key: 11,
              label: `最后修改人`,
              visible: true
          },
          {
              key: 12,
              label: `最后修改时间`,
              visible: true
          }
      ],
      // 总条数
      total: 0,
      // 拆分规则表格数据
      splitList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        params:{

        },
        searchValues: [],
        splitId: null,
        custId: null,
        siteCode: null,
        siteName: null,
        billType: null,
        billTypeName: null,
        splitType: null,
        splitTypeName: null,
        generalTicket: null,
        specialTicket: null,
        electricTicket: null,
        engineerTicket: null,
        splitRule: null,
        splitRuleName: null,
        splitSequence: null,
        splitSequenceName: null,
        splitRows: null,
        splitRowsName: null,
        maxRows: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },

      // 远程查询条件加载
      remoteSearchValueLoading: false,
      // 关键字查询条件
      searchValueOptions:[

      ],
      /* ======================================省市区======================================  */
      // 省
      provinceId: null,
      provinceList:[],
      // 市
      cityId: null,
      cityList:[],
      // 区
      districtId: null,
      districtList:[],

      /* ======================================查询条件-公司代码选择======================================  */
      searchsiteCodes:[],
      searchsiteCodenames:[],
      searchsiteCodeTotal: 0,
      searchsiteCodeList: [],
      searchsiteCodeDialogOpen: false,
      searchsiteCodeSelectLoading: false,
      searchsiteCodeQueryParams: {
          searchValue: null,
          pageNum: 1,
          pageSize: 20,
      },
      /* ======================================编辑-公司代码选择======================================  */
      siteCodename: null,
      siteCodeTotal: 0,
      siteCodeList: [],
      siteCodeDialogRadio: null,
      siteCodeDialogOpen: false,
      siteCodeSelectLoading: false,
      siteCodeQueryParams: {
          searchValue: null,
          pageNum: 1,
          pageSize: 20,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 行样式 */
    rowClass({ row, rowIndex }) {
      if (this.ids.includes(row.id)) {
          return { background: "#d9edf7", height:'20px' };
      } else {
          return { height:'20px'};
      }
    },
   /** 隐藏搜索按钮操作 */
   showSearchFun(isShowSearch){
      this.showSearch = isShowSearch
      let oldHeight = this.$refs.queryRef.$el.offsetHeight
      if(!isShowSearch){
          //当前是显示状态
          oldHeight = oldHeight + 12
      }else{
          oldHeight = oldHeight - 12
      }
      this.$nextTick(() => (
         this.tableHeight = this.$refs.tableRef.$el.offsetHeight - (this.$refs.queryRef.$el.offsetHeight-oldHeight)
      ))
    },
    /** 展开按钮操作 */
    toggleAdvanced() {
      const oldHeight = this.$refs.queryRef.$el.offsetHeight
      this.advanced = !this.advanced
      this.$nextTick(() => (
         this.tableHeight = this.$refs.tableRef.$el.offsetHeight - (this.$refs.queryRef.$el.offsetHeight-oldHeight)
      ))
    },
    /** 查询拆分规则列表 */
    getList() {
      this.loading = true;
      listSplit(this.queryParams).then(response => {
        this.splitList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        splitId: null,
        custId: null,
        siteCode: null,
        siteName: null,
        billType: null,
        billTypeName: null,
        splitType: null,
        splitTypeName: null,
        generalTicket: null,
        specialTicket: null,
        electricTicket: null,
        engineerTicket: null,
        splitRule: null,
        splitRuleName: null,
        splitSequence: null,
        splitSequenceName: null,
        splitRows: null,
        splitRowsName: null,
        maxRows: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },


      /* ※※ 查询 省市区 相关方法 start ※※ */
      // 获取省
      getProvinceList(){
          provinceList().then(response => {
              this.provinceList = response.data;
          });
      },
      // 获取市
      getCityList(){
          console.log(this.provinceId);
          cityList( {"parentId" : this.provinceId } ).then(response => {
              this.cityList = response.data;
          });
      },
      // 获取区县
      getDistrictList(){
          districtList( {"parentId" : this.cityId } ).then(response => {
              this.districtList = response.data;
          });
      },
      // 选中省份
      handleChangeProvince(val){
          // 给表单省字段赋值
          this.form.provinceid = val;
          let province = {};
          province = this.provinceList.find((item)=>{
              return item.id === val;
          });
          this.form.province = province.name;
          // 城市数据清空、区县数据清空;
          this.cityList = [];
          this.districtList = [];
          // 已选市、区数据清空
          this.cityId = null;
          this.districtId = null;
          // 表单城市、区县数据清空
          this.form.cityid = null;
          this.form.city = null;
          this.form.areaid = null;
          this.form.area = null;
          // 获取城市数据
          this.getCityList();
      },
      // 清空省份
      handleClearProvince(){
          // 城市数据清空、区县数据清空;
          this.cityList = [];
          this.districtList = [];
          // 已选市、区数据清空
          this.cityId = null;
          this.districtId = null;
          // 表单城市、区县数据清空
          this.form.cityid = null;
          this.form.city = null;
          this.form.areaid = null;
          this.form.area = null;
      },
      // 选中城市
      handleChangeCity(val){
          // 给表单市字段赋值
          this.form.cityid = val;
          let city = {};
          city = this.cityList.find((item)=>{
              return item.id === val;
          });
          this.form.city = city.name;
          // 区县数据清空
          this.districtList = [];
          // 已选区县清空
          this.districtId = null;
          // 表单区县清空
          this.form.areaid = null;
          this.form.area = null;
          // 获取城市数据
          this.getDistrictList();
      },
      // 清空省份
      handleClearCity(){
          // 区县数据清空
          this.districtList = [];
          // 已选区县清空
          this.districtId = null;
          // 表单区县清空
          this.form.areaid = null;
          this.form.area = null;
      },
      // 选中区县
      handleChangeDistrict(val){
          // 给表单省字段赋值
          this.form.areaid = val;
          let district = {};
          district = this.districtList.find((item)=>{
              return item.id === val;
          });
          this.form.area = district.name;
      },
      // 清空省份
      handleClearDistrict(){
          // 表单区县清空
          this.form.areaid = null;
          this.form.area = null;
      },

      /* ※※ 查询 省市区 相关方法 end ※※ */




    /* ※※ 查询 公司代码 相关方法 start ※※ */
    /** ① 弹出查询条件-公司代码 */
    openSearchsiteCodeDialogOpen(){
        this.searchsiteCodeDialogOpen = true;
        // 默认不查询
    },
    /** ② 单击行 **/
    handleSearchsiteCodeRowClick(row, column, event){
        this.$refs.searchsiteCodeSingleTable.toggleRowSelection(row);
    },
    /** ③ 行KEY **/
    getSearchsiteCodeListRowKey(row) {
        return row.companycode
    },
    /** ④ 选中公司代码 **/
    handleSearchsiteCodeSelectionChange(selection) {
        this.searchsiteCodes = selection.map(item => item.siteCode);
        this.searchsiteCodenames = selection.map(item => item.siteName);
    },
    /** ⑤ 点击查询按钮 **/
    handleSearchsiteCodeQuery(){
        this.searchsiteCodeQueryParams.pageNum = 1;
        this.getSearchsiteCodeList();
    },
    /** ⑥ 查询 **/
    getSearchsiteCodeList(){
        this.searchsiteCodeSelectLoading = true;
        listcompany(this.searchsiteCodeQueryParams).then(response => {
            this.searchsiteCodeList = response.rows;
            this.searchsiteCodeTotal = response.total;
            this.searchsiteCodeSelectLoading = false;
        });
    },
    /** ⑦ 点击确认查询 **/
    confirmSearchsiteCode() {
        if(this.searchsiteCodes.length > 0){
            this.queryParams.params.siteCodes = this.searchsiteCodes.join(',');
            this.queryParams.params.companynames = this.searchsiteCodenames.join(',');
        }
        // 关闭查询弹出框
        this.searchsiteCodeCancel();
    },
    /** ⑧ 点击关闭查询弹出框 **/
    searchsiteCodeCancel() {
        this.searchsiteCodeDialogOpen = false;
    },
    /* ※※ 查询 公司代码 相关方法 end ※※ */


    /* ※※ 编辑 公司代码 相关方法 start ※※ */
    /** ① 弹出编辑内容-公司代码 */
    opensiteCodeDialogOpen(){
        this.siteCodeDialogOpen = true;
        this.getsiteCodeList();
    },
    /** ② 单击行 **/
    handlesiteCodeRowClick(row, column, event){
        this.$refs.siteCodeSingleTable.toggleRowSelection(row);
    },
    /** ③ 行KEY **/
    getsiteCodeListRowKey(row) {
        return row.companycode
    },
    /** ④ 选中公司代码 **/
    handlesiteCodeSelectionChange(selection) {
        if (selection[0]) {
            this.siteCodeDialogRadio = selection[0]
            this.form.companycode = selection[0].companycode;
            this.form.companyname = selection[0].companyname;
        }
    },
    /** ⑤ 点击查询按钮 **/
    handlesiteCodeQuery(){
        this.siteCodeQueryParams.pageNum = 1;
        this.getsiteCodeList();
    },
    /** ⑥ 查询 **/
    getsiteCodeList(){
        this.siteCodeSelectLoading = true;
        listcompany(this.siteCodeQueryParams).then(response => {
            this.siteCodeList = response.rows;
            this.siteCodeTotal = response.total;
            this.siteCodeSelectLoading = false;
        });
    },
    /** ⑦ 点击确认查询 **/
    confirmsiteCode() {
        this.siteCodeCancel();
    },
    /** ⑧ 点击关闭查询弹出框 **/
    siteCodeCancel() {
        this.siteCodeDialogOpen = false;
    },
    /* ※※ 编辑 公司代码 相关方法 end ※※ */


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加拆分规则";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSplit(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改拆分规则";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSplit(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSplit(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除拆分规则编号为"' + ids + '"的数据项？').then(function() {
        return delSplit(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('saleconfig/split/export', {
        ...this.queryParams
      }, `split_${new Date().getTime()}.xlsx`)
    },
    /** 动态加载关键字查询条件 */
    remoteSearchValue(query) {
        this.remoteSearchValueLoading = true;
        if (query !== '') {
            this.searchValueOptions = [
                {value: '公司:' + query ,label: '公司:' + query },
            ];
            this.searchValueOptions.map(item => {
                this.queryParams.searchValues.map((item2, index) => {
                    if(item.value.startsWith('公司') && item2.startsWith('公司')){
                        item.disabled = true;
                    }
                })
            });
        } else {
            this.searchValueOptions = [];
        }
        this.remoteSearchValueLoading = false;
    },

  }
};
</script>
